package com.company.service.impl;

import com.company.entity.User;
import com.company.service.RegistService;
import java.util.Scanner;

public class RegistServiceImpl implements RegistService {
    Scanner sc=new Scanner(System.in);

    @Override
    public void execute() {
        while (true){
            System.out.println("请输入账号");
            String name=sc.next();
            System.out.println("请输入密码");
            String pswd=sc.next();
            System.out.println("请再次输入密码");
            String pased=sc.next();
            if (name.length()==0||pswd.length()==0){
                System.out.println("账号跟密码长度大于0");
                continue;
            }
            if(!pswd.equals(pased)){
                System.out.println("两次密码必须一致");
                continue;
            }
            User user =new User();
            user.setUsername(name);
            user.setPassword(pswd);
            int result=StartServiceImpl.userService.regist(user);
            if (result==0){
                System.out.println("用户名已存在,请重新输入");
                continue;
            }else{
                System.out.println("注册成功");
                break;
            }
        }


    }
}
